﻿using System;
using System.Windows.Data;
using Acando.Dynamics.CRM.Silverlight.Library.CrmSdk;

namespace Acando.Dynamics.CRM.Silverlight.Library.Converter
{
    public class CrmPartylistConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(String))
            {
                if (value == null)
                    return "";

                string s = string.Empty;
                foreach (activityparty p in (activityparty[])value)
                {
                    s += p.partyid.name + ';';
                }

                if ( s.Length > 0 )
                    s = s.Remove(s.Length - 1);

                return s;
            }
           else
                throw new NotSupportedException();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException(targetType.ToString());
        }

        #endregion
    }
}
